import time


def main():
    f = None
    try:
        f = open('data/aaa.txt', 'r', encoding='utf-8')
        # 一次性读取整个文件内容
        print(f.read())
        # 逐行读取
        for line in f:
            print('line = ', line, end='\n')
            time.sleep(0.5)
        # 按行读取到列表中
        lines = f.readlines()
        print('lines = ', lines, end='\n')

    except FileNotFoundError:
        print('file not found')
    except LookupError:
        print('error')
    except UnicodeDecodeError:
        print('unicode decode error')
    finally:
        if f:
            f.close()


if __name__ == '__main__':
    main()
